import { Component, Vue, Inject } from 'vue-property-decorator';

import { IUserShare } from '@/shared/model/user-share.model';
import UserShareService from './user-share.service';

@Component
export default class UserShareDetails extends Vue {
  @Inject('userShareService') private userShareService: () => UserShareService;
  public userShare: IUserShare = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.userShareId) {
        vm.retrieveUserShare(to.params.userShareId);
      }
    });
  }

  public retrieveUserShare(userShareId) {
    this.userShareService()
      .find(userShareId)
      .then(res => {
        this.userShare = res;
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
